// https://cn.redux.js.org/redux-toolkit/overview/
// yarn add @reduxjs/toolkit
import { configureStore } from '@reduxjs/toolkit'
import type { ThunkAction, Action } from '@reduxjs/toolkit'
// reducer => {key:value}
import reducer from '@/reducers'

const store = configureStore({
  reducer
})

// // 从 store 本身推断出 `RootState` 和 `AppDispatch` 类型
export type RootState = ReturnType<typeof store.getState>
// // 推断出类型: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch
// 指定中间件中disaptch这的类型
export type AppThunk<ReturnType = void> = ThunkAction<
  ReturnType,
  RootState,
  unknown,
  Action<string>
>

export default store
